'''
1、如果把根节点看做第 1 层，如何打印出每一个节点所在的层数？

2、如何打印出每个节点的左右子树各有多少节点？
'''

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def traver(root,level):
    if root is None:
        return
    
    print(f"节点 {root} 在第 {level} 层")
    traver(root.left,level + 1)
    traver(root.right,level + 1)
traver(root,1)

def count(root):
    if root is None:
        return 
    
    left = count(root.left)
    right = count(root.right)

    print(f"节点 {root} 的左子树有 {leftCount} 个节点，右子树有 {rightCount} 个节点")

    return left + right +1


'''
给你一棵二叉树，请你用分解问题的思路写一个 count 函数，计算这棵二叉树共有多少个节点
'''
def count(root):
    if root is None:
        return 
    
    left = count(root.left)
    right = count(root,right)
    return 1 + left + right


